<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">
    <link href="framework/reset.css" rel="stylesheet">
    <link href="css/orderList.css" rel="stylesheet">
    <script src="js/orderList.js"></script>
    <script src="https://fastly.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="js/pageJump.js"></script>
    <title>饿了么 我的订单</title>
</head>

<body>

    <div class="wrapper" id="app">

        <!-- header部分 -->
        <header>
            <p>我的订单</p>
        </header>

        <!-- 订单列表部分 -->
        <h3>未支付订单信息：</h3>
        <ul class="order">
            <li v-for="order in getPaidOrder" @click="jumpTo('payment.html?orderId='+order.order.orderId)">
                <div class="order-info">
                    <p>
                        {{order.restaurant.businessName}}
                        <i class="fa fa-caret-down"></i>
                    </p>
                    <div class="order-info-right">
                        <p>&#165;{{order.order.orderTotal}}</p>
                        <div class="order-info-right-icon">去支付</div>
                    </div>
                </div>
                <ul class="order-detailet">
                    <li v-for="food in order.foods">
                        <p>{{food.foodName}} x {{food.quantity}}</p>
                        <p>&#165;{{food.foodPrice}}</p>
                    </li>
                    
                    <li>
                        <p>配送费</p>
                        <p>&#165;{{order.restaurant.deliveryPrice}}</p>
                    </li>
                </ul>
            </li>
        
        </ul>

        <h3>已支付订单信息：</h3>
        <ul class="order">
            <li v-for="order in getdispayOrder">
                <div class="order-info">
                    <p>
                        {{order.restaurant.businessName}}
                        <i class="fa fa-caret-down"></i>
                    </p>
                    <div class="order-info-right">
                        <p>&#165;{{order.order.orderTotal}}</p>
                        <div class="order-info-right-icon">已支付</div>
                    </div>
                </div>
                <ul class="order-detailet">
                    <li v-for="food in order.foods">
                        <p>{{food.foodName}} x {{food.quantity}}</p>
                        <p>&#165;{{food.foodPrice}}</p>
                    </li>
                    
                    <li>
                        <p>配送费</p>
                        <p>&#165;{{order.restaurant.deliveryPrice}}</p>
                    </li>
                    
                </ul>
            </li>
            
        </ul>
        <ul class="footer">
            <li onclick="location.href='index.html'">
                <i class="fa fa-home"></i>
                <p>首页</p>
            </li>
            <li>
                <i class="fa fa-compass"></i>
                <p>发现</p>
            </li>
            <li onclick="location.href='orderList.html'">
                <i class="fa fa-file-text-o"></i>
                <p>订单</p>
            </li>
            <li>
                <i class="fa fa-user-o" @click="jumpTo('userAddress.html')"></i>
                <p>我的</p>
            </li>
        </ul>
    </div>
    <script>
        var path=getRequestPath()
        var app=new Vue({
            el:"#app",
            data:{
                
                orderList:[],
            },
            methods:{
                listOrders:function(){
                    axios.post(path+"/OrdersController/listOrdersByUserId",null,{
                        params:{
                            
                        },
                        headers:{
                            Authorization:this.getAuthorization()
                        }
                    }).then((respon)=>{
                        if(respon.data.code==200){
                            this.orderList=respon.data.detail
                        }
                    }).catch((error)=>{
                        console.log(error)
                    })
                },
                getAuthorization:function(){
                    return window.localStorage.getItem("Auth")
                },
                jumpTo:function(u){
                    window.location.href=u
                }
            },
            created(){
                this.listOrders()
            },
            computed:{
                getPaidOrder(){
                    console.log(this.orderList.filter(function(item){
                        return item.orderState==0
                    }))
                    return this.orderList.filter(function(item){
                        console.log(item)
                        return item.order.orderState==0
                    })
                },
                getdispayOrder(){
                    return this.orderList.filter(function(item){
                        return item.order.orderState==1
                    })
                }
            }
        })
    </script>
</body>

</html>